/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.matrimonysite.sessionbean;

import com.matrimonysite.entity.UserServicePackage;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author khanhnguyen
 */
@Stateless
public class UserServicePackageFacade extends AbstractFacade<UserServicePackage> {

    @PersistenceContext(unitName = "MatrimonySite-ejbPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public UserServicePackageFacade() {
        super(UserServicePackage.class);
    }

    @Override
    public void create(UserServicePackage userservicepackage) {
        em.persist(userservicepackage);
    }

    @Override
    public void edit(UserServicePackage userservicepackage) {
        em.merge(userservicepackage);
    }

    @Override
    public void remove(UserServicePackage userservicepackage) {
        em.remove(em.merge(userservicepackage));
    }

    public UserServicePackage getServiceID(String serviceID) {
        UserServicePackage userServicePackage = null;
        try {
            Query query = em.createNamedQuery("UserServicePackage.findByServiceID");
            query.setParameter("serviceID", serviceID);
            userServicePackage = (UserServicePackage) query.getSingleResult();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return userServicePackage;
    }

    public UserServicePackage getServiceName(String serviceName) {
        UserServicePackage userServicePackage = null;
        try {
            Query query = em.createNamedQuery("UserServicePackage.findByServiceName");
            query.setParameter("serviceName", serviceName);
            userServicePackage = (UserServicePackage) query.getSingleResult();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return userServicePackage;
    }

    public UserServicePackage getDescription(String description) {
        UserServicePackage userServicePackage = null;
        try {
            Query query = em.createNamedQuery("UserServicePackage.findByDescription");
            query.setParameter("description", description);
            userServicePackage = (UserServicePackage) query.getSingleResult();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return userServicePackage;
    }

    public UserServicePackage getPrice(String price) {
        UserServicePackage userServicePackage = null;
        try {
            Query query = em.createNamedQuery("UserServicePackage.findByPrice");
            query.setParameter("price", price);
            userServicePackage = (UserServicePackage) query.getSingleResult();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return userServicePackage;
    }

    public List<UserServicePackage> getAllUserServicePackage() {
        Query query = em.createNamedQuery("UserServicePackage.findAll");
        return query.getResultList();
    }
}
